import { _decorator, Animation, Component, Node, UITransform } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('bridgeController')
export class bridgeController extends Component {
    @property speed:number = 20;
    transform:UITransform = null;
    startUp:boolean = true;
    start() {
        this.init()
        this.delete()
    }
    init()
    {
        this.transform = this.node.getComponent(UITransform);
        console.log(this.transform)
    }
    //开始增长
    Up(deltaTime:number)
    {
        let width = this.transform.contentSize.width;
        let height = this.transform.contentSize.height
        this.transform.setContentSize(width,height += this.speed  * deltaTime)
    }
    //增长结束
    UpOk()
    {
        this.startUp = false;
        this.node.getComponent(Animation).play();
    }
    die()
    {
        this.node.destroy();
    }
    delete()
    {
        this.node.parent.parent.on('moveOk',()=>
        {
            const x = this.node.getPosition().x
            const height = this.node.getComponent(UITransform).contentSize.height
            if(x + height < -640)
            {
                this.node.destroy();
            }
        },this)
    }
    update(deltaTime: number) 
    {
        if(this.transform && this.startUp)
        {
            this.Up(deltaTime);
        }
    }
}


